﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Localization;

using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading.Tasks;

namespace Microsoft.Extensions.Localization.Mvc {
    [Route("Languages/[action]")]
    [ApiExplorerSettings(IgnoreApi = true)]
    public class LanguagesController:BaseController {
        [HttpPost]
        public IActionResult SetLanguage(string culture,string returnUrl) {
            Response.Cookies.Append(
                CookieRequestCultureProvider.DefaultCookieName,
                CookieRequestCultureProvider.MakeCookieValue(new RequestCulture(culture)),
                new CookieOptions { Expires = DateTimeOffset.UtcNow.AddYears(1) }
            );
            return LocalRedirect(returnUrl);
        }

    }
}
